// package com.yhl.login;
//
// /**
//  * @author: yanghl
//  * @description: 创建一个控制器来处理登录请求并返回 JWT
//  * @date: 2024/7/15 17:31
//  */
// import org.springframework.beans.factory.annotation.Autowired;
// import org.springframework.security.authentication.AuthenticationManager;
// import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
// import org.springframework.security.core.Authentication;
// import org.springframework.security.core.AuthenticationException;
// import org.springframework.security.core.userdetails.UserDetails;
// import org.springframework.security.core.userdetails.UserDetailsService;
// import org.springframework.web.bind.annotation.*;
//
// @RestController
// public class AuthController {
//
//     @Autowired
//     private AuthenticationManager authenticationManager;
//
//     @Autowired
//     private JwtUtil jwtUtil;
//
//     @PostMapping("/login")
//     public String createToken(@RequestBody AuthRequest authRequest) throws Exception {
//         try {
//             Authentication authentication = authenticationManager.authenticate(
//                     new UsernamePasswordAuthenticationToken(authRequest.getUsername(), authRequest.getPassword())
//             );
//         } catch (AuthenticationException e) {
//             throw new Exception("Invalid username or password");
//         }
//         return jwtUtil.generateToken(authRequest.getUsername());
//     }
// }
//
